package com.cs.manaer.controller;

import com.cs.manaer.controller.req.ListMenuReqMsg;
import com.cs.manaer.controller.req.ListRoleReqMsg;
import com.cs.manaer.controller.req.MenuReqMsg;
import com.cs.manaer.controller.req.RoleReqMsg;
import com.cs.manaer.controller.res.ListCsmgMenuResMsg;
import com.cs.manaer.service.CsmgMenuService;
import com.lin.common.error.CustomRuntimeException;
import com.lin.common.rest.ResMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;

@RestController
@RequestMapping("/web")
public class MenuController {

    @Autowired
    private CsmgMenuService csmgMenuService;

    @PostMapping("/listmenu")
    public ResMsg<ListCsmgMenuResMsg> listmenu(@Valid @RequestBody ListMenuReqMsg reqMsg) {
        ResMsg<ListCsmgMenuResMsg> urs = new ResMsg<>();
        return urs.withData(csmgMenuService.listmenu(reqMsg.getPageSize(), reqMsg.getPageNo()));
    }

    @PostMapping("/addmenu")
    public ResMsg<Integer> addmenu(@Valid @RequestBody MenuReqMsg reqMsg) throws Exception {
        ResMsg<Integer> rm = new ResMsg<>();
        return rm.withData(csmgMenuService.addmenu(reqMsg));
    }

    @PostMapping("/delmenu/{id}")
    public ResMsg<Integer> delmenu(@PathVariable Long id) {
        ResMsg<Integer> rm = new ResMsg<>();
        return rm.withData(csmgMenuService.delmenu(id));
    }
}
